from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.edge.service import Service as EdgeService
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time

# 设置浏览器驱动路径，这里以 Chrome 为例
edge_driver_path  = "/home/huangxin/webdriver/msedgedriver"


# 创建 Chrome 服务对象
edge_service  = EdgeService(executable_path=edge_driver_path)


# 创建 Chrome 浏览器对象，传递服务对象
driver = webdriver.Edge(service=edge_service )

# 打开登录页面
login_url = "https://www.aimatess.xyz/h5/#/pages/login/login"
driver.get(login_url)

# 等待页面加载完成，可以根据实际情况调整等待时间
time.sleep(2)
#
# 定位输入手机号的 input 元素
phone_input = driver.find_element(By.XPATH, "/html/body/uni-app/uni-page/uni-page-wrapper/uni-page-body/uni-view/uni-view[2]/uni-view[2]/uni-input/div/input")
passworld = driver.find_element(By.XPATH,"/html/body/uni-app/uni-page/uni-page-wrapper/uni-page-body/uni-view/uni-view[2]/uni-view[4]/uni-input/div/input")
login_button = driver.find_element(By.XPATH,"/html/body/uni-app/uni-page/uni-page-wrapper/uni-page-body/uni-view/uni-view[2]/uni-view[7]")
image_button = driver.find_element(By.XPATH,"/html/body/uni-app/uni-page/uni-page-wrapper/uni-page-body/uni-view/uni-view[2]/uni-view[6]/uni-image/img")
# 填写手机号 /html/body/uni-app/uni-page/uni-page-wrapper/uni-page-body/uni-view/uni-view[2]/uni-view[6]/uni-image/img
phone_input.send_keys("17620084608")
passworld.send_keys('asd1234567')
# 获取当前页面的 HTML，也可以通过其他方式获取需要的数据
# page_source = driver.page_source
# print(page_source)

image_button.click()
time.sleep(2)
login_button.click()

# 等待新页面加载完成
wait = WebDriverWait(driver, 10)

# sign_button_xpath = "/html/body/uni-app/uni-page/uni-page-wrapper/uni-page-body/uni-view/uni-view[4]/uni-view/uni-image[2]/img"
# sign_button = wait.until(EC.presence_of_element_located((By.XPATH, sign_button_xpath)))

# sign_button.click()
# time.sleep(2)

home_button_xpath = "/html/body/uni-app/uni-page/uni-page-wrapper/uni-page-body/uni-view/uni-view[8]/uni-view/uni-view[1]/uni-view[1]/uni-view[4]/uni-view/uni-image/img"
home_button=wait.until(EC.presence_of_element_located((By.XPATH, home_button_xpath)))
home_button.click()

wait = WebDriverWait(driver, 10)



# 关闭浏览器
# driver.quit()
